import { Tag, Image } from 'ant-design-vue';
import type { TableColumn } from '@/components/core/dynamic-table';
export type TableListItem = API.CaseManagementPageResultItem;
export type TableColumnItem = TableColumn<TableListItem>;

const checkerName = (sponsor, organizer) => {
  if (sponsor && organizer) {
    return sponsor + '，' + organizer;
  } else if (sponsor == '') {
    return organizer;
  } else if (organizer == '') {
    return sponsor;
  }
};

const caseStatus = (val) => {
  switch (val) {
    case 1:
      return '立案';
    case 2:
      return '调查取证';
    case 3:
      return '案件处理';
    case 4:
      return '结案归档';
    case 5:
      return '已结束';
    default:
      return '-';
  }
};

const caseTextColor = (val) => {
  switch (val) {
    case 1:
      return 'color: #10A0AD';
    case 2:
      return 'color: #F5820F';
    case 3:
      return 'color: #1677FF';
    case 4:
      return 'color: #363687';
    case 5:
      return 'color: #09B840';
    default:
      return 'color: #999999';
  }
};

export const cmColumns: TableColumnItem[] = [
  {
    title: '关键词',
    dataIndex: 'keyword',
    hideInTable: true,
    formItemProps: {
      labelWidth: 55,
      componentProps: () => {
        return {
          placeholder: '请输入案件来源、案由搜索',
          autocomplete: 'off',
          disabledLabelWidth: true,
        };
      },
    },
  },
  {
    title: '案件状态',
    dataIndex: 'status',
    hideInTable: true,
    formItemProps: {
      component: 'Select',
      componentProps: ({ formInstance, formModel, tableInstance }) => ({
        options: [
          {
            label: '全部',
            value: -1,
          },
          {
            label: '立案',
            value: 1,
          },
          {
            label: '调查取证',
            value: 2,
          },
          {
            label: '案件处理',
            value: 3,
          },
          {
            label: '结案归档',
            value: 4,
          },
          {
            label: '已结束',
            value: 5,
          },
        ],
      }),
      defaultValue: -1,
    },
  },
  {
    title: '时间筛选',
    dataIndex: 'rangePicker',
    hideInTable: true,
    formItemProps: {
      component: 'RangePicker',
      componentProps: () => {
        return {
          format: 'YYYY/MM/DD',
          valueFormat: 'YYYY/MM/DD',
        };
      },
    },
  },
  {
    title: '案件来源',
    align: 'left',
    dataIndex: 'sourceName',
    hideInSearch: true,
  },
  {
    title: '案由',
    align: 'left',
    dataIndex: 'caseActionName',
    hideInSearch: true,
  },
  {
    title: '执法机构',
    align: 'left',
    dataIndex: 'agencyName',
    hideInSearch: true,
  },
  {
    title: '案件状态',
    align: 'left',
    dataIndex: 'status',
    hideInSearch: true,
    customRender: ({ record }) => (
      <div style={caseTextColor(record.status)}>{caseStatus(record.status)}</div>
    ),
  },
  {
    title: '执法人员',
    align: 'left',
    dataIndex: 'sponsor',
    hideInSearch: true,
    customRender: ({ record }) => checkerName(record.sponsor, record.organizer),
  },
  {
    title: '提交时间',
    align: 'left',
    dataIndex: 'createTime',
    hideInSearch: true,
  },
];
